package com.yicong.ants.manager;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.util.Log;
import android.util.Pair;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentActivity;

import com.abedelazizshe.lightcompressorlibrary.CompressionListener;
import com.abedelazizshe.lightcompressorlibrary.VideoCompressor;
import com.abedelazizshe.lightcompressorlibrary.VideoQuality;
import com.abedelazizshe.lightcompressorlibrary.config.Configuration;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import com.bumptech.glide.request.target.Target;
import com.cchao.simplelib.LibCore;
import com.cchao.simplelib.core.AndroidHelper;
import com.cchao.simplelib.core.CollectionHelper;
import com.cchao.simplelib.core.ImageLoader;
import com.cchao.simplelib.core.JsonHelper;
import com.cchao.simplelib.core.Logs;
import com.cchao.simplelib.core.PrefHelper;
import com.cchao.simplelib.core.RxBus;
import com.cchao.simplelib.core.RxHelper;
import com.cchao.simplelib.core.UiHelper;
import com.cchao.simplelib.ui.activity.BaseActivity;
import com.cchao.simplelib.ui.interfaces.BaseView;
import com.cchao.simplelib.util.CallBacks;
import com.cchao.simplelib.util.NumHelper;
import com.cchao.simplelib.util.StringHelper;
import com.cchao.simplelib.util.ThreadHelper;
import com.cchao.simplelib.util.UrlUtil;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.bean.ShareBean;
import com.yicong.ants.bean.account.DashBoard;
import com.yicong.ants.bean.base.RespBean;
import com.yicong.ants.bean.video.GiftListBean;
import com.yicong.ants.bean.video.VideoListBean;
import com.yicong.ants.databinding.DialogShareLayoutBinding;
import com.yicong.ants.manager.business.Dialogs;
import com.yicong.ants.manager.config.ZzConfigs;
import com.yicong.ants.manager.http.RetrofitHelper;
import com.yicong.ants.utils.AmapHelper;
import com.yicong.ants.utils.AppUtils;
import com.yicong.ants.utils.CacheUtils;
import com.yicong.ants.utils.InitUtil;
import com.yicong.ants.utils.L;
import com.yicong.ants.utils.ToastUtils;
import com.yicong.ants.view.CommonPop;
import com.yicong.ants.view.dialog.GpsDialog;
import com.yicong.ants.view.dialog.VoucherCodeDialog;
import com.yicong.ants.viewmodel.AppStartViewModel;
import com.zhy.http.okhttp.callback.FileCallBack;

import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import okhttp3.Call;

/**
 * 业务累
 *
 * @author cch
 * @version 2020/4/3
 */
public class BusinessHelper {

    private final static Map<String, String> ScenicTypeMap = new HashMap<>();
    public final static Map<String, Integer> ScenicLabelMap = new HashMap<>();
    public final static Map<String, Boolean> mVideoFocus = new HashMap<>();
    public static DashBoard mDashBoard;
    public static List<GiftListBean> mGiftList;
    public static Set<String> mVids = new HashSet<>();
    public static String mActivityId = "";
    public static String mSignScanContent = "";
    public static boolean mEnergyRewardTip = false;

    static {
        ScenicTypeMap.put(Constants.Scenic_Type.All, "景区");
        ScenicTypeMap.put(Constants.Scenic_Type.DiscountScenic, "特惠景区");
        ScenicTypeMap.put(Constants.Scenic_Type.AdvanceScenic, "预约景区");
        ScenicTypeMap.put(Constants.Scenic_Type.PartnerScenic, "免预约景区");
        ScenicTypeMap.put(Constants.Scenic_Type.FreeScenicType, "免费景区");
        ScenicTypeMap.put(Constants.Scenic_Type.SetPartnerAdvance, "预约景区");

        ScenicLabelMap.put(Constants.Scenic_Type.All, R.drawable.scenic_list_ic_type1);
        ScenicLabelMap.put(Constants.Scenic_Type.DiscountScenic, 0);
        ScenicLabelMap.put(Constants.Scenic_Type.AdvanceScenic, R.drawable.scenic_list_ic_type1);
        ScenicLabelMap.put(Constants.Scenic_Type.PartnerScenic, R.drawable.scenic_list_ic_type4);
    }

    public static void showDev() {
        UiHelper.showToast("开发中");
    }

    public static String getScenicType(String scenicType) {
        return ScenicTypeMap.get(scenicType);
    }

    public static void showTouristQr(Window window, Context context, String url) {
        CommonPop.Builder mQrCodeBuilder = new CommonPop.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.popup_window_my_entry_qr_code, null);
        CommonPop mQrCodePop = mQrCodeBuilder.setView(view)
                .setBackGroundLevel(0.7f)
                .setOutsideTouchable(true)
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .setAnimationStyle(R.style.MyPopupWindow_alpha_style)
                .create();
        ImageView ivCancel = view.findViewById(R.id.iv_cancel);
        ivCancel.setOnClickListener(v -> mQrCodePop.dismiss());
        ImageView ivQrCode = view.findViewById(R.id.iv_qr_code);
        ImageLoader.loadImage(ivQrCode, url);
        mQrCodePop.showAtLocation(window.getDecorView(), Gravity.CENTER, 0, 0);
    }

    public static void sendVerifyCode(BaseView baseView, Runnable runnable) {
        Disposable disposable = RetrofitHelper.getApis().sendVerifyCode(Collections.emptyMap())
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    baseView.hideProgress();
                    baseView.showToast(respBean.getMsg());
                    if (respBean.isCodeFail()) {
                        return;
                    }
                    runnable.run();
                }, RxHelper.getHideProgressConsumer(baseView));
    }

    public static String getScenicCanUseCoin(String scenicType) {
        if (UserManager.notLogin()) {
            return "";
        }

        if (Constants.Scenic_Type.PartnerScenic.equals(scenicType)) {
            return "";
        }

        return "仓库可用 " + UserManager.getUserBean().getStock() + " 门票";
    }

    public static String getMobileMix(String mobile) {
        if (StringHelper.isEmpty(mobile)) {
            return "";
        }
        if (mobile.length() < 8) {
            return "";
        }
        return mobile.substring(0, 3) + "****" + mobile.substring(7);
    }

    public static String getIdCardNameMix(String id_card_name) {
        if (StringHelper.isEmpty(id_card_name)) {
            return "";
        }
        if (id_card_name.length() <= 1) {
            return "*";
        }
        return "*" + id_card_name.substring(1);
    }

    public static String adClick(String id_card_name) {
        if (StringHelper.isEmpty(id_card_name)) {
            return "";
        }
        if (id_card_name.length() <= 1) {
            return "*";
        }
        return "*" + id_card_name.substring(1);
    }

    /**
     * 分享蚁丛链接
     *
     * @param activity
     * @param title
     * @param link
     */
    public static void shareAntLink(Activity activity, String title, String link) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, "【复制内容，打开蚁丛旅游App即可查看】\n" + title + '\n' + link);
        intent.setType("text/plain");
        activity.startActivity(intent);
    }

    public static void shareWx(Activity activity, String text, String imageUrl, String link, Runnable callBack) {
        shareWx(activity, UiHelper.getString(R.string.app_name), text, imageUrl, link, callBack);
    }

    public static void shareWx(Activity activity, String title, String desc, String thumb, String link, Runnable callBack) {
        if (StringHelper.isEmpty(link)) {
            return;
        }

        title = URLDecoder.decode(title);
        desc = URLDecoder.decode(desc);
        link = URLDecoder.decode(link);
        thumb = URLDecoder.decode(thumb);

        Logs.d("shareWx 0" + link + " image " + thumb);

        if (!link.contains("refer_uid") && UserManager.isLogin()) {
            link = UrlUtil.appendParameterCompat(link, "refer_uid", UserManager.getUserId());
        }
        if (StringHelper.isEmpty(title)) {
            title = UiHelper.getString(R.string.app_name);
        }

        if (StringHelper.isEmpty(thumb)) {
            thumb = Constants.Url.Favicon_Image;
        }

//        UMImage image = new UMImage(activity, thumb);
//        UMWeb web = new UMWeb(link);
//        web.setTitle(title);//标题
//        web.setThumb(image);  //缩略图
//        web.setDescription(desc);

//        Logs.d("shareWx " + link + " image " + thumb);

        String finalDesc = desc;

        String finalLink = link;
        String finalThumb = thumb;
        String finalTitle = title;

        BottomSheetDialog dialog = new BottomSheetDialog(activity);
        DialogShareLayoutBinding mBind = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_share_layout, null, false);
//        dialog.setContentView(mBind.getRoot());
        dialog.show();
        Dialogs.requestDialogWidth90(dialog, mBind.getRoot());

        mBind.shareWx.setOnClickListener(v1 -> {
            dialog.cancel();
            shareType(activity, finalTitle, finalDesc, finalThumb, finalLink, SHARE_MEDIA.WEIXIN, callBack);
        });
        mBind.shareWxcircle.setOnClickListener(v12 -> {
            dialog.cancel();
            shareType(activity, finalTitle, finalDesc, finalThumb, finalLink, SHARE_MEDIA.WEIXIN_CIRCLE, callBack);
        });

        mBind.shareYchat.setOnClickListener(v13 -> {
            if (!AppUtils.isInstallByread(Constants.YChat_package_name)) {
                ToastUtils.show(LibCore.getContext(), "未安装蚁聊App，无法分享", Toast.LENGTH_LONG);
                return;
            }
            ShareBean bean = new ShareBean();
            bean.setDesc(finalDesc)
                    .setTitle(finalTitle)
                    .setImage(finalThumb)
                    .setLink(finalLink);
            ComponentName cn = new ComponentName(Constants.YChat_package_name, Constants.YChat_Activity);
            Intent intent = new Intent(Constants.YChat_Action);
            intent.setComponent(cn);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, JsonHelper.toJson(bean));
            intent.putExtra("type", 3);
            activity.startActivity(intent);
            dialog.cancel();

        });
        mBind.tvCancel.setOnClickListener(v14 -> {
            dialog.dismiss();
        });

    }

    public static void shareType(Activity activity, String title, String desc, String thumb, String link, SHARE_MEDIA media, Runnable callBack) {
        UMImage image = new UMImage(activity, thumb);
        UMWeb web = new UMWeb(link);
        web.setTitle(title);//标题
        web.setThumb(image);  //缩略图
        web.setDescription(desc);

        new ShareAction(activity)
                .withMedia(web)
                .withText(desc)
                .setPlatform(media)
                .setCallback(new UMShareListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onResult(SHARE_MEDIA share_media) {
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                        Logs.d(throwable.getMessage() + "  " + throwable.getLocalizedMessage());
                        UiHelper.showToast(throwable.getMessage());
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media) {

                    }
                })
                .share();
        if (callBack != null) {
            callBack.run();
        }
    }

    /**
     * 仓库转入转出
     */
    public static void onStockTrans(BaseActivity baseStateView, int type, String amount, String payPwd, Runnable sucRunnable) {
        baseStateView.showProgress();
        Map<String, String> map = new HashMap<>();
        map.put("type", String.valueOf(type));
        map.put("pay_pwd", payPwd);
        map.put("amount", amount);
        baseStateView.addSubscribe(RetrofitHelper.getApis().transferStock(map)
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    baseStateView.hideProgress();
                    if ("3010".equals(respBean.code)) {
                        UiHelper.showConfirmDialog(baseStateView, respBean.getMsg(), null);
                        return;
                    }
                    baseStateView.showToast(respBean.getMsg());
                    if (respBean.isCodeFail()) {
                        return;
                    }
                    if (sucRunnable != null) {
                        sucRunnable.run();
                    }
                }, RxHelper.getHideProgressConsumer(baseStateView)));
    }

    /**
     * 仓库转入转出
     */
    public static void onYcStockTrans(BaseActivity baseStateView, int type, String amount, String payPwd, Runnable sucRunnable) {
        //10转入
        baseStateView.showProgress();
        Map<String, String> map = new HashMap<>();
        map.put("pay_pwd", payPwd);
        map.put("amount", amount);
        Observable<RespBean> observable;
        if (type == 10) {
            observable = RetrofitHelper.getApis().ycToStock(map);
        }else{
            observable = RetrofitHelper.getApis().stockToYc(map);
        }
        baseStateView.addSubscribe(observable
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    baseStateView.hideProgress();
                    if ("3010".equals(respBean.code)) {
                        UiHelper.showConfirmDialog(baseStateView, respBean.getMsg(), null);
                        return;
                    }
                    baseStateView.showToast(respBean.getMsg());
                    if (respBean.isCodeFail()) {
                        return;
                    }
                    if (sucRunnable != null) {
                        sucRunnable.run();
                    }
                }, RxHelper.getHideProgressConsumer(baseStateView)));
    }

    /**
     * 加载配置文件
     */
    public static void loadIndexConfig(CallBacks.Bool callBacks) {
        // 加载通知
        Map<String, String> map = new HashMap<>();
        map.put("version", AppUtils.getVersionName(LibCore.getContext()));
        try {
            map.put("phoneBrand", Build.BRAND);
            AmapHelper.LocationInfo locationInfo = AmapHelper.getLocationInfo();
            if (locationInfo != null) {
                map.putAll(JsonHelper.toMap(JsonHelper.toJson(locationInfo), String.class));
            }
        } catch (Exception ex) {
            Logs.logException(ex);
        }

        Disposable subscribe = RetrofitHelper.getApis().indexConfig(map)
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    if (respBean.isCodeFail()) {
                        UiHelper.showToast(respBean.getMsg());
                        return;
                    }
                    ZzConfigs.updateIndexConfig(respBean.getData());
                    downloadSplash();
                    RxBus.get().postEvent(Constants.Event.Config_Update);
                    InitUtil.INSTANCE.initLiveSDK(LibCore.getContext());
                    //更新协议版本号
                    int version = PrefHelper.getInt(AppStartViewModel.KEY_PRIVACY_AGREED, -1);
                    if (version == 0 || version == -1) {
                        int newVersion = ZzConfigs.getClientConf().getWebUrl("ant_privacy").version;
                        PrefHelper.putInt(AppStartViewModel.KEY_PRIVACY_AGREED, newVersion);
                    }
                    if (callBacks != null) {
                        callBacks.onCallBack(true);
                    }
                }, throwable -> {
                    Logs.logException(throwable);
                    if (callBacks != null) {
                        callBacks.onCallBack(false);
                    }
                });
    }

    /**
     * 下载启动图
     */
    public static void downloadSplash() {
        if (CollectionHelper.isNotEmpty(ZzConfigs.mIndexInfo.getSplash())) {
            for (String url : ZzConfigs.mIndexInfo.getSplash()) {
                boolean cache = CacheUtils.isCache(url);
                if (!cache) {
                    FutureTarget<File> fileFutureTarget = Glide.with(LibCore.getContext())
                            .load(url)
                            .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
                }
            }
        }
    }

    /**
     * 加载短视频礼物
     */
    public static void loadVideoGift(CompositeDisposable disposable, CallBacks.Bool callBack) {
        if (CollectionHelper.isNotEmpty(mGiftList)) {
            callBack.onCallBack(true);
            return;
        }
        disposable.add(RetrofitHelper.getApis().getGiftList()
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    if (respBean.isCodeFail()) {
                        UiHelper.showToast(respBean.getMsg());
                        callBack.onCallBack(false);
                        return;
                    }

                    mGiftList = respBean.getData();
                    callBack.onCallBack(true);
                }, RxHelper.getErrorConsumer()));
    }

    public static void checkPublishTip(Activity activity, Runnable runnable) {
        if (UserManager.notLogin()) {
            UiHelper.showToast("请先登录");
            return;
        }

        String content = AppHelper.getUmConfig("publish_limit_tip"
                , "发布功能暂只对星级用户开放。严禁发布反政府、涉黑、涉毒、涉黄等不当言论，若情节严重平台将会采取封号处理");

        Runnable runnable2 = () -> {
            if ("0".equals(UserManager.getUserBean().getLevel())) {
                UiHelper.showToast("您还不是星级用户，暂不支持发布");
                return;
            }
            runnable.run();
        };

        Dialogs.showDisclaimer(activity, "发布说明", content, Constants.Prefs.Circle_Content_Publish_Tip, runnable2);
    }

    /**
     * 总扣除门票 = 转赠数/(1-手续费率）
     * 手续费扣除 = 转赠数/(1-手续费率）x 手续费率
     * <p>
     * 如  转赠 75，总扣除=  75/0.75 = 100
     * 手续费 = 75/0.75*0.25 = 25
     *
     * @return Pair  first=tax,  total=总计
     */
    public static Pair<String, String> calTax(float amount, float taxTate) {
        String tax = NumHelper.float5StripZero(amount * taxTate);
        String total = NumHelper.float5StripZero(Float.parseFloat(tax) + amount);
        return Pair.create(tax, total);
    }

    public static String generatingRandomString() {
        String randomCode = "";
        String model = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
        char[] m = model.toCharArray();
        for (int j = 0; j < 6; j++) {
            char c = m[(int) (Math.random() * 52)];
            randomCode += c;
        }
        return randomCode;
    }

    public static void saveVid(String vid) {
        mVids.add(vid);
        List<String> list_1 = new ArrayList<>(mVids);
        String s = StringUtils.join(list_1.toArray(), ",");
        PrefHelper.putString(Constants.Prefs.Vids, s);
    }

    // 后台发起服务，上送看过视频的vid
    public static void uploadVids(CompositeDisposable disposable) {
        String vids = PrefHelper.getString(Constants.Prefs.Vids);
        if (StringHelper.isEmpty(vids)) {
            return;
        }
        L.i("看过视频的vid : " + vids);

        Map<String, String> map = new HashMap<>();
        map.put("vids", vids);
        disposable.add(RetrofitHelper.getApis()
                .videoHistory(map)
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    if (respBean.isCodeSuc()) {
                        PrefHelper.remove(Constants.Prefs.Vids);
                    }
                }, RxHelper.getErrorConsumer()));
    }

    public static void showVourchCode(CompositeDisposable disposable, FragmentActivity activity) {
        HashMap<String, String> map = new HashMap<>(4);
        disposable.add(RetrofitHelper.getApis()
                .refreshCertCode(map)
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    if (!respBean.isCodeSuc()) {
                        ToastUtils.showShort(activity, respBean.getMsg());
                        return;
                    }
                    VoucherCodeDialog.newInstance(activity).setVoucherCode(respBean.getData()).show(activity.getSupportFragmentManager());
                }, RxHelper.getErrorConsumer()));
    }

    public static void putFollow(String uid, boolean b) {
        mVideoFocus.put(uid, b);
        RxBus.get().postEvent(Constants.Event.Video_Follow_Update);
    }

    /**
     * 获取必要权限
     */
    public static boolean checkPermission(FragmentActivity activity) {
        if (AndroidHelper.hasPermissions(Constants.LOCATION)) {
            return true;
        }
        Disposable subscribe = new RxPermissions(activity)
                .request(Constants.LOCATION)
                .subscribe(aBoolean -> {
                    // 未获取到
                    if (!aBoolean) {
                        UiHelper.showLongToast("请授予应用的必要的权限");
                    }
                });
        return false;
    }

    public static boolean mVideoDownloading = false;

    public static void downloadVideo(VideoListBean item, Activity activity) {
        if (StringHelper.isEmpty(item.getUrl())) {
            return;
        }
        mVideoDownloading = true;
        String savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AntDownload/";
        String fileName = "ant_" + item.getVid() + '_' + System.currentTimeMillis() + ".mp4";
        HttpManager.getHttp(item.getUrl(), null, new FileCallBack(savePath, fileName) {
            @Override
            public void onError(Call call, Exception e, int id) {
                L.e("Exception------->", e.getMessage());
                UiHelper.showToast("视频下载失败，请检查网络");
                mVideoDownloading = false;
            }

            @Override
            public void inProgress(float progress, long total, int id) {
                super.inProgress(progress, total, id);
                int pro = (int) (progress * 100);
                L.i("BusinessHelper", "下载进度... " + pro + '%');
                mVideoDownloading = true;
            }

            @Override
            public void onResponse(File file, int id) {
                L.d("视频下载成功，fileName = " + file.getName());
                UiHelper.showToast("视频下载成功");
                // 刷新到相册
                Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                intent.setData(Uri.fromFile(file));
                activity.sendBroadcast(intent);
                mVideoDownloading = false;
            }
        });
    }


    public static boolean checkGps(FragmentActivity activity, Runnable sucCallBack) {
        LocationManager lm = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
        if (lm.getAllProviders().contains(LocationManager.GPS_PROVIDER)
                && !lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            GpsDialog.newInstance(activity)
                    .setConvertListener(() -> {
                        Intent intent1 = new Intent();
                        intent1.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        activity.startActivity(intent1);
                    }).show(activity.getSupportFragmentManager());
            return false;
        }
        sucCallBack.run();
        return true;
    }

    public static void compressVideo2(String videoLocal, CallBacks.Int compressCallBack) {
        ThreadHelper.execute(() -> {
            try {
                if (new File(ImageHelper.mCompressOutputPath).exists()) {
                    new File(ImageHelper.mCompressOutputPath).delete();
                }
            } catch (Exception exception) {
                Logs.logException(exception);
            }
        });

        VideoCompressor.start(LibCore.getContext()
                , Uri.fromFile(new File(videoLocal)) // => Source can be provided as content uri, it requires context.
                , null
                , new File(ImageHelper.mCompressOutputPath).getAbsolutePath()
                , null /*String, or null*/
                , new CompressionListener() {
                    @Override
                    public void onStart() {
                        // Compression start
                    }

                    @Override
                    public void onSuccess() {
                        // On Compression success
                        compressCallBack.onCallBack(200);
                    }

                    @Override
                    public void onFailure(String failureMessage) {
                        Logs.i("VideoCompressor", "onFailure: " + failureMessage);
                        // On Failure
                    }

                    @Override
                    public void onProgress(float v) {
                        UiHelper.runOnUiThread(() -> compressCallBack.onCallBack((int) v));
                    }

                    @Override
                    public void onCancelled() {
                        // On Cancelled
                    }
                }, new Configuration(
                        VideoQuality.MEDIUM,
                        24, /*frameRate: int, or null*/
                        false,
                        null /*videoBitrate: int, or null*/
                )
        );
    }

}
